<?php
defined('IN_MAIN') or exit('Invalid Access!');

function calc_ad_cost($duration, $type_id, $type_detail, $payment_type, $ad=""){
$cost=($duration+(is_array($ad)? (is_numeric($ad["day"])? $ad["day"] : 0) : 0))*($payment_type=="g"? $type_detail[$type_id]["cost_gold"] : $type_detail[$type_id]["cost"]);//calculate cost as new duration add-on + ad's remaining day (if update), or just duration (id add new)
$old_remain_cost=(is_array($ad)? (is_numeric($ad["day"])? $ad["day"] : 0) : 0)*($payment_type=="g"? $type_detail[$ad["tid"]]["cost_gold"] : $type_detail[$ad["tid"]]["cost"]);//if changing ad type, the old remain cost=new ad type rate*ad's remaining day
$total_cost=$cost-$old_remain_cost;//refund the old remaining cost
$total_cost=$total_cost<0? 0 : $total_cost;
return $total_cost;
}
?>